<template>
  <div class="container">
    <el-card class="login-card">
      <el-form @submit.native.prevent='login'>
        <el-form-item label='用户名'>
          <el-input v-model="model.username"></el-input>
        </el-form-item>
        <el-form-item label='密码'>
          <el-input type='password' v-model="model.password"></el-input>
        </el-form-item>
        <el-button type='primary' native-type='submit'>登录</el-button>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      model: {},
    };
  },
  methods: {
    async login() {
      const res = await this.$http.post("login", this.model);
      // 接收到token保存到localstoage中
      localStorage.token = res.data.token;
      localStorage.username = res.data.username;
      this.$router.push("/");
      this.$message({
        type: "success",
        message: `欢迎您 尊贵的:${res.data.username}管理员`,
      });
    },
  },
};
</script>

<style>
.login-card {
  width: 25rem;
  margin: 6rem auto;
}
/* html {
  background: url("../assets/login-bg.jpg") no-repeat top center;
} */
</style>
